package com.u1zz.zeus.module.iot.dal.mysql.device;

import java.util.*;

import com.u1zz.zeus.framework.common.pojo.PageParam;
import com.u1zz.zeus.framework.common.pojo.PageResult;
import com.u1zz.zeus.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.u1zz.zeus.framework.mybatis.core.mapper.BaseMapperX;
import com.u1zz.zeus.module.iot.dal.dataobject.device.DeviceDO;
import org.apache.ibatis.annotations.Mapper;
import com.u1zz.zeus.module.iot.controller.admin.device.vo.*;

/**
 * 设备 Mapper
 *
 * @author u1zz
 */
@Mapper
public interface DeviceMapper extends BaseMapperX<DeviceDO> {
    default LambdaQueryWrapperX<DeviceDO> getListQueryWrapper(DeviceListReqVO reqVO) {
        return new LambdaQueryWrapperX<DeviceDO>()
                .eqIfPresent(DeviceDO::getDeviceKey, reqVO.getDeviceKey())
                .likeIfPresent(DeviceDO::getDeviceName, reqVO.getDeviceName())
                .eqIfPresent(DeviceDO::getProductId, reqVO.getProductId())
                .eqIfPresent(DeviceDO::getDescription, reqVO.getDescription())
                .eqIfPresent(DeviceDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(DeviceDO::getActiveTime, reqVO.getActiveTime())
                .betweenIfPresent(DeviceDO::getLastOnlineTime, reqVO.getLastOnlineTime())
                .eqIfPresent(DeviceDO::getDeviceSecret, reqVO.getDeviceSecret())
                .eqIfPresent(DeviceDO::getVersion, reqVO.getVersion())
            .orderByDesc(DeviceDO::getId);    }
    default PageResult<DeviceDO> selectPage(DeviceListReqVO reqVO, PageParam pageParam) {
        return selectPage(pageParam, getListQueryWrapper(reqVO));

    }
    default List<DeviceDO> selectList(DeviceListReqVO reqVO) {
        return selectList(getListQueryWrapper(reqVO));

    }


}